home *** CD-ROM | disk | FTP | other *** search
/ Skunkware 98 / Skunkware 98.iso / src / net / omniORB-2.5.0-src.tar.gz / omniORB-2.5.0-src.tar / omniORB_2.5.0 / include / omniORB2 / omniInternal.h < prev    next >
C/C++ Source or Header  |  1998-02-27  |  19KB  |  525 lines

  1. // -*- Mode: C++; -*-
  2. //                            Package   : omniORB2
  3. // omniInternal.h             Created on: 6/2/96
  4. //                            Author    : Sai Lai Lo (sll)
  5. //
  6. //    Copyright (C) 1996, 1997 Olivetti & Oracle Research Laboratory
  7. //
  8. //    This file is part of the omniORB library
  9. //
  10. //    The omniORB library is free software; you can redistribute it and/or
  11. //    modify it under the terms of the GNU Library General Public
  12. //    License as published by the Free Software Foundation; either
  13. //    version 2 of the License, or (at your option) any later version.
  14. //
  15. //    This library is distributed in the hope that it will be useful,
  16. //    but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. //    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  18. //    Library General Public License for more details.
  19. //
  20. //    You should have received a copy of the GNU Library General Public
  21. //    License along with this library; if not, write to the Free
  22. //    Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  
  23. //    02111-1307, USA
  24. //
  25. //
  26. // Description:
  27. //    *** PROPRIETORY INTERFACE ***
  28. //    
  29.  
  30. /*
  31.   $Log: omniInternal.h,v $
  32.   Revision 1.18  1998/02/27 14:00:17  sll
  33.   Changed manager() to _objectManager() in class omniObject to avoid
  34.   potential name clash with application code.
  35.  
  36.  * Revision 1.17  1998/01/27  16:06:45  ewc
  37.  * Added support necessary for TypeCode and Any
  38.  *
  39.  * Revision 1.16  1998/01/20  16:46:18  sll
  40.  * Removed obsolute variable omni::traceLevel.
  41.  *
  42.   Revision 1.15  1997/12/15 15:26:32  sll
  43.   Added the missing dllimport/dllexport for WIN32.
  44.  
  45.   Revision 1.14  1997/12/12 19:59:19  sll
  46.   Added version variable omniORB_x_y.
  47.  
  48.   Revision 1.13  1997/12/10 11:52:31  sll
  49.   *** empty log message ***
  50.  
  51.   Revision 1.12  1997/12/09 20:45:54  sll
  52.   Added support for system exception handlers.
  53.   Added support for late bindings.
  54.  
  55.  * Revision 1.11  1997/09/20  16:23:53  dpg1
  56.  * Added second argument, is_cxx_type to _widenFromTheMostDerivedIntf().
  57.  * Added a new hash table of wrapped objects, and a mutex for it, for
  58.  * LifeCycle support.
  59.  *
  60.   Revision 1.10  1997/08/26 15:25:26  sll
  61.   Removed initFile.h include.
  62.  
  63.   Revision 1.9  1997/05/06 16:09:13  sll
  64.   Public release.
  65.  
  66.  */
  67.  
  68. #ifndef __OMNIINTERNAL_H__
  69. #define __OMNIINTERNAL_H__
  70.  
  71. #include <assert.h>
  72. #include <iostream.h>
  73.  
  74. #include <stddef.h>
  75.  
  76. #if !defined(__atmos__) && !defined(_WIN32)
  77. #include <strings.h>
  78. #else
  79. #include <string.h>
  80. #endif
  81. #include <omniORB2/CORBA_sysdep.h>
  82. #include <omniORB2/CORBA_basetypes.h>
  83. #include <omniORB2/seqtemplates.h>
  84. #include <omniORB2/IOP.h>
  85. #include <omniORB2/GIOP.h>
  86. #include <omniORB2/IIOP.h>
  87. #include <omnithread.h>
  88.  
  89. class Rope;
  90. class GIOP_S;
  91. class GIOP_C;
  92. class GIOPobjectLocation;
  93. class omniObject;
  94. class initFile;
  95. class omniORB;
  96. class omniObjectManager;
  97.  
  98. // omniORB_x_y
  99. //   Define this variable to trap the mismatch of the stub and the runtime
  100. //   library. The two digits x,y should be the same as the shared library
  101. //   major version number and minor version number. For example, for shared
  102. //   library 2.5.0 the variable number should be omniORB_2.5. Notice that
  103. //   the variable name stays the same with compatible shared library, e.g.
  104. //   2.5.1.
  105. //
  106. extern const char* _OMNIORB2_NTDLL_ omniORB_2_5;
  107.  
  108. #include <omniORB2/rope.h>
  109.  
  110. struct omniObjectKey {
  111.   _CORBA_ULong hi;
  112.   _CORBA_ULong med;
  113.   _CORBA_ULong lo;
  114. };
  115.  
  116. class _OMNIORB2_NTDLL_ omni {
  117.  
  118. public:
  119.  
  120. #if SIZEOF_PTR == SIZEOF_LONG
  121.   typedef long ptr_arith_t;
  122. #elif SIZEOF_PTR == SIZEOF_INT
  123.   typedef int ptr_arith_t;
  124. #else
  125. #error "No suitable type to do pointer arithmetic"
  126. #endif
  127.  
  128.   static const _CORBA_Boolean myByteOrder;
  129.  
  130.   enum alignment_t { ALIGN_1 = 1, ALIGN_2 = 2, ALIGN_4 = 4, ALIGN_8 = 8 };
  131.   static const alignment_t max_alignment;  // Maximum value of alignment_t
  132.  
  133.   static inline ptr_arith_t align_to(ptr_arith_t p,alignment_t align) {
  134.     return (p + ((int) align - 1)) & ~((int) align - 1);
  135.   }
  136.  
  137.   static _CORBA_Unbounded_Sequence_Octet myPrincipalID;
  138.  
  139.   static void objectIsReady(omniObject *obj);
  140.   static void objectDuplicate(omniObject *obj);
  141.   // Increment the reference count.
  142.  
  143.   static void objectRelease(omniObject *obj);
  144.   // Decrement the reference count. The count must be >= 0, otherwise
  145.   // throw a INV_OBJREF() exception.
  146.   // If the reference count is 0, then
  147.   //     Remove the object from one of the object table depends on
  148.   //     whether it is a proxy or an implementation.
  149.   //     if this is a proxy object, call the delete operator to remove
  150.   //        the object
  151.   //     else this is the implementation, then
  152.   //          if the object has been marked to be disposed of, then
  153.   //              call the delete operator
  154.   //          else defer calling the delete operator until a subsequent
  155.   //          call to BOA::dispose().
  156.  
  157.   static omniObject *locateObject(omniObjectManager*,omniObjectKey &k);
  158.   static void disposeObject(omniObject *obj);
  159.   // If the reference count of the object is 0, call the delete operator
  160.   // to remove the object.
  161.   // If the reference count of the object is not 0, then
  162.   //    if this is a proxy object, simply returns.
  163.   //    else this is the implementation, then
  164.   //         *MARK the object as disposed but it defer calling the
  165.   //          delete operator until the reference count drops to zero.
  166.  
  167.  
  168.   static char *objectToString(const omniObject *obj);
  169.   // returns a heap allocated and stringified IOR representation
  170.   // (ref CORBA 2 spec. 10.6.5)
  171.  
  172.   static omniObject *stringToObject(const char *str);
  173.   // returns an object pointer identified by the stringified IOR representation
  174.   // (ref CORBA 2 spec. 10.6.5)
  175.   // returns 0 if this is a null object reference
  176.  
  177.   static omniObject * createObjRef(const char *mostDerivedRepoId,
  178.                    const char *targetRepoId,
  179.                    IOP::TaggedProfileList* profiles,
  180.                    _CORBA_Boolean release);
  181.   // Returns an object pointer identified by <mostDerivedRepoId> & <profiles>.
  182.   // If release is TRUE, the returned object assumes resposibility of
  183.   // the heap allocated <profiles>.
  184.   // <mostDerivedRepoId> is the interface repository ID recorded in the
  185.   // original IOR.
  186.   // <targetRepoId> is the interface repository ID of the desired interface.
  187.   // If <targetRepoId> is neither equal to <mostDerivedRepoId> nor the
  188.   // latter is a derived interface of the former, a CORBA::MARSHAL exception
  189.   // would be raised.
  190.   // If <targetRepoId> == 0, then the desired interface is the pseudo object
  191.   // CORBA::Object from which all interfaces derived.
  192. };
  193.  
  194. class omniRopeAndKey {
  195. public:
  196.   inline omniRopeAndKey(Rope *r,_CORBA_Octet *k, _CORBA_ULong ksize) 
  197.                  : pd_r(r), pd_keysize(0)
  198.   {
  199.     key(k,ksize);
  200.   }
  201.  
  202.   inline omniRopeAndKey() : pd_r(0), pd_keysize(0) {}
  203.  
  204.   inline ~omniRopeAndKey() { 
  205.     if (pd_keysize > sizeof(omniObjectKey)) {
  206.       delete [] pd_keyptr;
  207.     }
  208.   }
  209.  
  210.   inline Rope* rope() const { return pd_r; }
  211.  
  212.   inline _CORBA_Octet* key() const { 
  213.     if (pd_keysize <= sizeof(omniObjectKey)) {
  214.       return (_CORBA_Octet*)&pd_key; 
  215.     }
  216.     else {
  217.       return pd_keyptr; 
  218.     }
  219.   }
  220.    
  221.   inline _CORBA_ULong  keysize() const { return pd_keysize; }
  222.  
  223.   inline void rope(Rope* r) { pd_r = r; }
  224.   inline void key(_CORBA_Octet* k, _CORBA_ULong ksize) {
  225.     if (pd_keysize > sizeof(omniObjectKey)) delete [] pd_keyptr;
  226.     pd_keysize = ksize;
  227.     if (pd_keysize <= sizeof(omniObjectKey)) {
  228.       memcpy((void *)&pd_key,(void*)k,pd_keysize);
  229.     }
  230.     else {
  231.       pd_keyptr = new _CORBA_Octet[pd_keysize];
  232.       memcpy((void*)pd_keyptr,(void*)k,pd_keysize);
  233.     }
  234.   }
  235.  
  236. private:
  237.   Rope*             pd_r;
  238.   _CORBA_ULong      pd_keysize;
  239.   union {
  240.     _CORBA_Octet*   pd_keyptr;
  241.     omniObjectKey   pd_key;
  242.   };
  243.  
  244.   omniRopeAndKey& operator=(const omniRopeAndKey&);
  245.   omniRopeAndKey(const omniRopeAndKey&);
  246. };
  247.  
  248. class omniObject {
  249.  
  250. protected:
  251.  
  252.   omniObject(omniObjectManager*p =0); // ctor local object
  253.   omniObject(const char *repoId,   // ctor for proxy object
  254.      Rope *r,
  255.      _CORBA_Octet *key,
  256.      size_t keysize,
  257.            IOP::TaggedProfileList *profiles,
  258.      _CORBA_Boolean release); 
  259.   // If release TRUE, the object assumes management of the heap allocated
  260.   // <key> and <profiles>.
  261.  
  262.   virtual ~omniObject();
  263.  
  264.   void  PR_IRRepositoryId(const char *s);
  265.   // Set the IR repository ID of this object to <s>.
  266.   // NOTE: this function is **not thread-safe**. It *should not* be called
  267.   //       if there is any chance that the object might be accessed
  268.   //       concurrently by another thread.
  269.   // If this is a local object
  270.   //    1. If omni::objectIsReady() has been called for this object,
  271.   //       this function will throw a omniORB::fatalException().
  272.   //    2. otherwise, <s> is recorded as the current IR repository ID.
  273.   //
  274.   // If this is a proxy object
  275.   //    1. The IR repository ID of this object was initialised by the
  276.   //       ctor for proxy objects. This value is preserved.
  277.   //    2. <s> is then recorded as the current IR repository ID.
  278.   //    3. An internal flag (pd_flags.existent_and_type_verified) is set to 0.
  279.   //       This will cause assertObjectExistent() to check the type and
  280.   //       verify the existent of the object before it performs the next
  281.   //       invocation.
  282.  
  283. public:
  284.  
  285.   void setRopeAndKey(const omniRopeAndKey& l,_CORBA_Boolean keepIOP=1);
  286.   // Set new values to the rope and key. If keepIOP is true, keep the
  287.   // original IOP profile. Otherwise update the profile as well.
  288.   // This function is thread-safe.
  289.  
  290.   void resetRopeAndKey();
  291.   // If this is a proxy object, reset the rope and key to the values
  292.   // stored in the IOP profile.
  293.   // This function has no effect on local objects and is silently ignored.
  294.   // This function is thread-safe.
  295.  
  296.   _CORBA_Boolean getRopeAndKey(omniRopeAndKey& l) const;
  297.   // Get the current value of the rope and key. If the values are the same
  298.   // as those stored in the IOP profile, the return value is 0. Otherwise
  299.   // the return value is 1.
  300.   // This function is thread-safe.
  301.  
  302.   void getKey(_CORBA_Octet*& key,_CORBA_ULong& ksize) const {
  303.     // This is a non-thread safe function to read the key of this object.
  304.     // The object continues to own the storage of <key>.
  305.     // If the key is modified concurrently by another thread's call to
  306.     // setRopeAndKey(), the behaviour is underfine.
  307.     if (is_proxy()) {
  308.       key = pd_objkey.foreign;
  309.     }
  310.     else {
  311.       key = (_CORBA_Octet*) &pd_objkey.native;
  312.     }
  313.     ksize = pd_objkeysize;
  314.   }
  315.   
  316.  
  317.   void assertObjectExistent();
  318.   // If this is a local object, 
  319.   //       returns.
  320.   // If this is a proxy object
  321.   //     if the internal flag (pd_flags.existent_and_type_verified) is 0
  322.   //          contact the remote object to verify that it exists
  323.   //          and is of the type identified by the IR repository ID
  324.   //          given as the argument to the ctor of this object.
  325.   //          Set pd_flags.existent_and_type_verified to 1
  326.   //          returns
  327.   //     else
  328.   //          returns
  329.   //
  330.   // This function may throw a CORBA::SystemException if 
  331.   //    1. the object does not exist - CORBA::OBJECT_NOT_EXIST
  332.   //    2. non-transient communication failure - CORBA::COMM_FAILURE
  333.   //    3. the object is of the wrong type - CORBA::INV_OBJREF
  334.   //    4. other system errors.
  335.   //
  336.   // This function is thread-safe.
  337.  
  338.   virtual _CORBA_Boolean dispatch(GIOP_S &,const char *operation,
  339.                   _CORBA_Boolean response_expected);
  340.   // Normally, this function is overridden by a dispatch function in the
  341.   // skeleton implementation stub. The function is called by the dispatcher
  342.   // of GIOP_S.
  343.   // This function is thread-safe.
  344.  
  345.   inline _CORBA_Boolean is_proxy() const { 
  346.     return (_CORBA_Boolean)pd_flags.proxy; 
  347.   }
  348.   // Return 1 if this is a proxy object, 0 if this is a local object.
  349.   // This function is thread-safe.
  350.  
  351.   inline const char *NP_IRRepositoryId() const { return pd_repoId; }
  352.   // Return the IR repository ID of this object. The value is returned 
  353.   // is either the value given to the ctor or set by the most recent
  354.   // call to PR_IRRepositoryID().
  355.   // This function is thread-safe.
  356.  
  357.   virtual void *_widenFromTheMostDerivedIntf(const char *type_id,
  358.                          _CORBA_Boolean is_cxx_type_id=0);
  359.   // The most derived class which override this virtual function will be
  360.   // called to return a pointer to the base class object identified by
  361.   // the type id <type_id>. 
  362.   //
  363.   // This function accepts two forms of type id:
  364.   //   if <is_cxx_type_id> == 0
  365.   //      <type_id> is a OMG IR repository ID. Furthermore, if <type_id> is
  366.   //      null, a pointer to the base class CORBA::Object will be returned.
  367.   //      The most derived class is guaranteed to support the widening to
  368.   //      all of the base classes that implement the base IDL interfaces.
  369.   //   if <is_cxx_type_id> == 1
  370.   //      <type_id> is a C++ class name of the target base class. For example
  371.   //      the base class CORBA::Object can be obtained by using 
  372.   //      "CORBA::Object" as the <type_id>. 
  373.   //      The most derived class may support the widening to a subset of its
  374.   //      base classes. It may even support none at all.
  375.   //
  376.   // If the object cannot be widened to the class specified, a
  377.   // null pointer will be returned.
  378.   // This function DO NOT throw any exception under any circumstance.
  379.   // This function is thread-safe.
  380.  
  381.   inline IOP::TaggedProfileList * iopProfiles() const { 
  382.     // This function is thread-safe.
  383.     return pd_iopprofile; 
  384.   }
  385.  
  386.   _CORBA_Boolean _real_is_a(const char *repoId);
  387.   // Returns 1 if the object is really an instance of the type identified
  388.   // by the IR repository ID <repoId>. If the stub for the object type is
  389.   // linked into the executable, the ORB can fully determine the _is_a
  390.   // relation without the need to contact the object remotely. Otherwise,
  391.   // the ORB will use the CORBA::Object::_is_a operation to query the
  392.   // remote object to find out its actual type.
  393.   //
  394.   // This function is thread-safe.
  395.  
  396.   void* _realNarrow(const char* repoId);
  397.   // If the actual type of the object can be widened to the requested interface
  398.   // type identified by the IR repository ID <repoId>, return a valid
  399.   // object reference. Otherwise, return 0. The return value is of type void*
  400.   // and can be casted to the T_ptr type of the interface T directly.
  401.   // The resulting T_ptr instance should be released using CORBA::release()
  402.   // when it is no longer needed.
  403.   // This function is thread-safe.
  404.  
  405.   void* _transientExceptionHandler(void*& cookie);
  406.   // If a transientExceptionHandler_t has been installed for this object
  407.   // by _transientExceptionHandler(void*,void*), returns this handler and its
  408.   // associated opaque argument in cookie.
  409.   // Otherwise return 0.
  410.   // This function is thread-safe.
  411.  
  412.   void _transientExceptionHandler(void* new_handler,void* cookie);
  413.   // Set the transientExceptionHandler_t of this object.  By default,
  414.   // i.e. when this function is not called for an object, the global
  415.   // transientExceptionHandler_t will be invoked when a CORBA::TRANSIENT
  416.   // exception is caught in a remote call from a proxy object.
  417.   // The argument <cookie> is an opaque argument that will be passed
  418.   // to the exception handler.
  419.   // This function is thread-safe.
  420.  
  421.   void* _commFailureExceptionHandler(void*& cookie);
  422.   // If a commFailureExceptionHandler_t has been installed for this object
  423.   // by _commFailureExceptionHandler(void*,void*), returns this handler and its
  424.   // associated opaque argument in cookie.
  425.   // Otherwise return 0.
  426.   // This function is thread-safe.
  427.  
  428.   void _commFailureExceptionHandler(void* new_handler,void* cookie);
  429.   // Set the commFailureExceptionHandler_t of this object.  By default,
  430.   // i.e. when this function is not called for an object, the global
  431.   // commFailureExceptionHandler_t will be invoked when a CORBA::COMM_FAILURE
  432.   // exception is caught in a remote call from a proxy object.
  433.   // The argument <cookie> is an opaque argument that will be passed
  434.   // to the exception handler.
  435.   // This function is thread-safe.
  436.  
  437.   void* _systemExceptionHandler(void*& cookie);
  438.   // If a systemExceptionHandler_t has been installed for this object
  439.   // by _systemExceptionHandler(void*,void*), returns this handler and its
  440.   // associated opaque argument in cookie.
  441.   // Otherwise return 0.
  442.   // This function is thread-safe.
  443.  
  444.   void _systemExceptionHandler(void* new_handler,void* cookie);
  445.   // Set the systemExceptionHandler_t of this object.  By default,
  446.   // i.e. when this function is not called for an object, the global
  447.   // systemExceptionHandler_t will be invoked when a CORBA::SystemException
  448.   // exception, other than CORBA::TRANSIENT and CORBA::COMM_FAILURE is caught 
  449.   // in a remote call from a proxy object. The handlers for CORBA::TRANSIENT
  450.   // and CORBA::COMM_FAILURE are installed their own install functions.
  451.   // The argument <cookie> is an opaque argument that will be passed
  452.   // to the exception handler.
  453.   // This function is thread-safe.
  454.  
  455.   omniObjectManager* _objectManager() const { return pd_manager; }
  456.   // This function should only be called for local object.
  457.   // Returns the object manager of this object.
  458.   // Calling this function for a proxy object would result in undefined
  459.   // behaviour.
  460.  
  461.   static omni_mutex          objectTableLock;
  462.   static omniObject*         proxyObjectTable;
  463.   static omniObject**        localObjectTable;
  464.   static omni_mutex          wrappedObjectTableLock;
  465.   static void**              wrappedObjectTable;
  466.  
  467.   static void                globalInit();
  468.   // This function is not thread-safe and should be called once only.
  469.  
  470.   static omniObjectManager*  nilObjectManager();
  471.  
  472. private:
  473.   union {
  474.     _CORBA_Octet *foreign;
  475.     omniObjectKey     native;
  476.   }                             pd_objkey;
  477.   size_t                        pd_objkeysize;
  478.   char *                        pd_repoId;
  479.   size_t                        pd_repoIdsize;
  480.   char *                        pd_original_repoId;
  481.   union {
  482.     Rope *                      pd_rope;
  483.     omniObjectManager*          pd_manager;
  484.   };
  485.   int                           pd_refCount;
  486.   omniObject *                      pd_next;
  487.  
  488.   struct {
  489.     _CORBA_UShort              proxy                       : 1;
  490.     _CORBA_UShort              disposed                    : 1;
  491.     _CORBA_UShort              existent_and_type_verified  : 1;
  492.     _CORBA_UShort              forwardlocation             : 1;
  493.     _CORBA_UShort              transient_exception_handler : 1;
  494.     _CORBA_UShort              commfail_exception_handler  : 1;
  495.     _CORBA_UShort              system_exception_handler    : 1;
  496.   } pd_flags;
  497.   
  498.   IOP::TaggedProfileList *      pd_iopprofile;
  499.   
  500.   inline int getRefCount() const { return pd_refCount; }
  501.   inline void setRefCount(int count) { pd_refCount = count; return; }
  502.  
  503.   friend void omni::objectIsReady(omniObject *obj);
  504.   friend void omni::objectDuplicate(omniObject *obj);
  505.   friend omniObject *omni::locateObject(omniObjectManager*,omniObjectKey &k);
  506.   friend void omni::disposeObject(omniObject *obj);
  507.   friend void omni::objectRelease(omniObject *obj);
  508.   friend char* omni::objectToString(const omniObject *obj);
  509.   friend omniObject* omni::stringToObject(const char *str);
  510.   friend omniObject * omni::createObjRef(const char *mostDerivedRepoId,
  511.                      const char *targetRepoId,
  512.                      IOP::TaggedProfileList *profiles,
  513.                      _CORBA_Boolean release);
  514. };
  515.  
  516. #include <omniORB2/bufferedStream.h>
  517. #include <omniORB2/giopDriver.h>
  518.  
  519. template <class T>
  520. class _CORBA_ConstrType_Variable_Var;
  521.  
  522. class tcParseEngine;
  523.  
  524. #endif // __OMNIINTERNAL_H__
  525.